package com.zr.service.car.Impl

import com.github.pagehelper.PageHelper
import com.zr.mapper.car.WorkMapper
import com.zr.mapper.lease.OrderMapper
import com.zr.service.car.WorkServer
import com.zr.util.TokenUtil
import com.zr.vo.CarWorkSelectBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.util.*
import javax.annotation.Resource

@Service
class WorkServerImpl:WorkServer {
    @Resource
    val workMapper: WorkMapper?=null

    @Autowired
    val tokenUtil:TokenUtil?=null
    override fun listByCarWorkSelectBean(workBean: CarWorkSelectBean): MutableList<CarWorkSelectBean>? {
        PageHelper.startPage<Any>(workBean.pageNum, workBean.pageSize)
        return workMapper?.listByCarWorkSelectBean(workBean)
    }

    override fun fitCar(workBean: CarWorkSelectBean) {
        //要修改car_work表，先把一个Work对象查询出来
        val work=workMapper?.selectByOrderId(workBean.orderId)
        work?.status="已整备"
        work?.outFitTime= Date()
        work?.outFitUserId=tokenUtil?.userId
        workMapper?.updateByPrimaryKeySelective(work)
    }

    override fun outCar(workBean: CarWorkSelectBean) {
        val work=workMapper?.selectByOrderId(workBean.orderId)
        work?.carNo=workBean.carNo
        work?.status="已出车"
        work?.outTime=Date()
        work?.outUserId=tokenUtil?.userId
        workMapper?.updateByPrimaryKeySelective(work)
    }

    override fun inCar(workBean: CarWorkSelectBean) {
        val work=workMapper?.selectByOrderId(workBean.orderId)
        work?.inTime=Date()
        work?.status="已回车"
        work?.inUserId=tokenUtil?.userId
        work?.total=workBean.total
        work?.mark=workBean.mark
        workMapper?.updateByPrimaryKeySelective(work)
    }
}